﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DcsGauges.Gui.Gauges.Interfaces;
using System.Diagnostics;

namespace DcsGauges.Data
{
    class TwoWayDataConnector : IDataConnector
    {
        #region Fields & Properties

        private ITriggerGauge                       gauge                   = null;
        private IDcsA10DataModel                    dataModel               = null;

        #endregion


        #region Constructors

        public TwoWayDataConnector(ITriggerGauge gauge, IDcsA10DataModel model)
        {
            this.gauge                  = gauge;
            this.dataModel              = model;
            this.gauge.TriggerEvent     += new EventHandler<TriggerValueEventArgs>(OnGaugeHandleTriggerEvent);
        }

        #endregion


        #region Interface Implementation

        public void Update()
        {
        }

        #endregion


        #region Event Handlers

        private void OnGaugeHandleTriggerEvent(object sender, TriggerValueEventArgs e)
        {
            Debug.Assert(this.gauge.DataProperty == e.DcsProperty);
            this.dataModel.IssueCommand(this.gauge.DataProperty, e.NewValue);
        }

        #endregion
    }
}
